package org.akomantoso.core.io.util.group;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.akomantoso.core.data.Act;
import org.akomantoso.core.data.Amendment;
import org.akomantoso.core.data.AmendmentList;
import org.akomantoso.core.data.Bill;
import org.akomantoso.core.data.Debate;
import org.akomantoso.core.data.DebateReport;
import org.akomantoso.core.data.Doc;
import org.akomantoso.core.data.DocumentCollection;
import org.akomantoso.core.data.Judgement;
import org.akomantoso.core.data.OfficialGazette;
import org.akomantoso.core.data.group.DocumentType;
import org.akomantoso.core.io.util.Instantiator;

/**
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 */
public final class DocumentTypeGroup {

	private DocumentTypeGroup() {
	}

	public static final Map<String, Instantiator<DocumentType>> MAP;

	static {

		Map<String, Instantiator<DocumentType>> temp = new HashMap<String, Instantiator<DocumentType>>();

		// officialGazette
		temp.put(OfficialGazette.ELEMENT, new Instantiator<DocumentType>() {
			public OfficialGazette instantiate() {
				return new OfficialGazette();
			}
		});

		// amendmentList
		temp.put(AmendmentList.ELEMENT, new Instantiator<DocumentType>() {
			public AmendmentList instantiate() {
				return new AmendmentList();
			}
		});

		// Amendment
		temp.put(Amendment.ELEMENT, new Instantiator<DocumentType>() {
			public Amendment instantiate() {
				return new Amendment();
			}
		});

		// judgement
		temp.put(Judgement.ELEMENT, new Instantiator<DocumentType>() {
			public Judgement instantiate() {
				return new Judgement();
			}
		});

		// debateReport
		temp.put(DebateReport.ELEMENT, new Instantiator<DocumentType>() {
			public DebateReport instantiate() {
				return new DebateReport();
			}
		});

		// doc
		temp.put(Doc.ELEMENT, new Instantiator<DocumentType>() {
			public Doc instantiate() {
				return new Doc();
			}
		});

		// Debate
		temp.put(Debate.ELEMENT, new Instantiator<DocumentType>() {
			public Debate instantiate() {
				return new Debate();
			}
		});

		// documentCollection
		temp.put(DocumentCollection.ELEMENT, new Instantiator<DocumentType>() {
			public DocumentCollection instantiate() {
				return new DocumentCollection();
			}
		});

		// bill
		temp.put(Bill.ELEMENT, new Instantiator<DocumentType>() {
			public Bill instantiate() {
				return new Bill();
			}
		});

		// act
		temp.put(Act.ELEMENT, new Instantiator<DocumentType>() {
			public Act instantiate() {
				return new Act();
			}
		});

		MAP = Collections.unmodifiableMap(temp);
	}

	public static DocumentType instantiate(String element) {

		final Instantiator<? extends DocumentType> instatiator = MAP.get(element);

		if (instatiator == null) {
			throw new RuntimeException("Tag [" + element + "] not supported DocumentType ?!?");
		}

		return instatiator.instantiate();
	}

}
